package com.suarte.webapp.action;

import com.suarte.core.PaymentType;
import com.suarte.core.EmployeeType;

import java.io.Serializable;
import org.appfuse.service.GenericManager;

/**
 * @date   Jan 04, 2011
 * @author Gcastillo
 */
public class EmployeeTypeForm extends BasePage implements Serializable {
    private GenericManager<EmployeeType, Long> employeeTypeManager;
    private EmployeeType employeeType = new EmployeeType();
    private Long id;

    public void setEmployeeTypeManager(GenericManager<EmployeeType, Long> employeeTypeManager) {
        this.employeeTypeManager = employeeTypeManager;
    }

    public EmployeeType getEmployeeType() {
        return employeeType;
    }

    public void setEmployeeType(EmployeeType employeeType) {
        this.employeeType = employeeType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        employeeTypeManager.remove(employeeType.getId());
        addMessage("employeeType.deleted");

        return "list";
    }

    public String edit() {
        if (id != null) {
            employeeType = employeeTypeManager.get(id);
        } else {
            employeeType = new EmployeeType();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (employeeType.getId() == null);
        employeeTypeManager.save(employeeType);

        String key = (isNew) ? "employeeType.added" : "employeeType.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
}